package com.android.bandroid.base;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
import android.widget.Toast;

import com.android.bandroid.core.CoreService;

/**
 *
 */
public abstract class BaseActivity extends FragmentActivity {
    public Context context;               //  上下文实例
    public BaseApplication application;    //  应用全局的实例
    public CoreService coreService;        //  核心层实例
    private Toast mToast;                  //   统一弹窗


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);      //  去掉title
        super.onCreate(savedInstanceState);
        context = getApplicationContext();
        application = (BaseApplication) this.getApplication();
        coreService = application.getCoreService();
    }

    /**
     * activity跳转
     *
     * @param toClass
     */
    public void openActivity(Class<?> toClass) {
        Intent intent = new Intent(this, toClass);
        super.startActivity(intent);
    }

    /**
     * activity跳转(finish本页)
     *
     * @param toClass
     */
    public void openActivityFinish(Class<?> toClass) {
        Intent intent = new Intent(this, toClass);
        super.startActivity(intent);
        finish();
    }

    /**
     * 统一弹出提示
     *
     * @param pMessage
     */
    @SuppressWarnings("static-access")
    public void showToast(String pMessage) {
        if (mToast == null) {
            mToast = new Toast(this).makeText(BaseActivity.this, pMessage, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(pMessage);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }
}
